package com.yunfeng.aolin.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.yunfeng.aolin.dao.CusQuotesRecordDAO;
import com.yunfeng.aolin.entity.CusQuotesRecord;
import com.yunfeng.aolin.service.CusQuotesRecordService;
import com.yunfeng.common.util.Page;
import com.yunfeng.common.util.PageUtils;

@Service
@Transactional
public class CusQuotesRecordServiceImpl implements CusQuotesRecordService {

	@Autowired
	private CusQuotesRecordDAO cusQuotesRecordDAO;

	/**
	 * @param id
	 * @return
	 * @see com.yunfeng.aolin.service.CusQuotesRecordService#get(java.lang.Long)
	 */
	@Override
	public CusQuotesRecord get(Long id) {
		return cusQuotesRecordDAO.findOne(id);
	}

	/**
	 * @param cusQuotesRecord
	 * @see com.yunfeng.aolin.service.CusQuotesRecordService#saveOrUpdate(com.yunfeng.aolin.entity.CusQuotesRecord)
	 */
	@Override
	public void saveOrUpdate(CusQuotesRecord cusQuotesRecord) {
		cusQuotesRecordDAO.save(cusQuotesRecord);
	}

	/**
	 * @param id
	 * @see com.yunfeng.aolin.service.CusQuotesRecordService#delete(java.lang.Long)
	 */
	@Override
	public void delete(Long id) {
		cusQuotesRecordDAO.delete(id);
	}

	@Override
	public List<CusQuotesRecord> findAll() {
		// TODO Auto-generated method stub
		return cusQuotesRecordDAO.findAll();
	}

	/**
	 * @param page
	 * @return
	 * @see com.yunfeng.aolin.service.CusQuotesRecordService#findAll(com.ketayao.ketacustom.util.dwz.Page)
	 */
	@Override
	public List<CusQuotesRecord> findAll(Page page) {
		org.springframework.data.domain.Page<CusQuotesRecord> springDataPage = cusQuotesRecordDAO
				.findAll(PageUtils.createPageable(page));
		page.setTotalCount(springDataPage.getTotalElements());
		return springDataPage.getContent();
	}

	/**
	 * @param page
	 * @param liaohao
	 * @return
	 * @see com.yunfeng.aolin.service.CusQuotesRecordService#findByLiaohao(com.ketayao.ketacustom.util.dwz.Page,
	 *      java.lang.String)
	 */
	@Override
	public List<CusQuotesRecord> findByLiaohao(Page page, String liaohao) {
		org.springframework.data.domain.Page<CusQuotesRecord> springDataPage = cusQuotesRecordDAO
				.findByLiaohaoContaining(liaohao,
						PageUtils.createPageable(page));
		page.setTotalCount(springDataPage.getTotalElements());
		return springDataPage.getContent();
	}

	/**
	 * 
	 * @param specification
	 * @param page
	 * @return
	 * @see com.yunfeng.aolin.service.CusQuotesRecordService#findByExample(org.springframework.data.jpa.domain.Specification,
	 *      com.ketayao.ketacustom.util.dwz.Page)
	 */
	@Override
	public List<CusQuotesRecord> findByExample(
			Specification<CusQuotesRecord> specification, Page page) {
		org.springframework.data.domain.Page<CusQuotesRecord> springDataPage = cusQuotesRecordDAO
				.findAll(specification, PageUtils.createPageable(page));
		page.setTotalCount(springDataPage.getTotalElements());
		return springDataPage.getContent();
	}
}
